package com.lebang.medicalInquiry;


import com.lebang.medicalInquiry.component.NettyLiveComponent;
import lombok.extern.slf4j.Slf4j;
import com.lebang.medicalInquiry.component.NettyComponent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.util.concurrent.CompletableFuture;

/**
 * @version V1.0
 * @author: zpc
 * @date:
 */
@EnableAsync
@EnableTransactionManagement
@SpringBootApplication
@Slf4j
public class MedicalInquiryServerApplication implements CommandLineRunner {
    @Autowired
    private NettyComponent nettyComponent;
    @Autowired
    private NettyLiveComponent nettyLiveComponent;

    public static void main(String[] args) {
        SpringApplication.run(MedicalInquiryServerApplication.class, args);
    }

    @Override
    public void run(String... args) {
        {
            CompletableFuture<Void> componentStartFuture = CompletableFuture.runAsync(() -> {
                log.info("聊天服务启动中");
                nettyComponent.start();
            });

            CompletableFuture<Void> liveComponentStartFuture = CompletableFuture.runAsync(() -> {
                log.info("直播服务启动中");
                nettyLiveComponent.start();
            });

            CompletableFuture.allOf(componentStartFuture, liveComponentStartFuture).join();
        }


    }
}
